"""
API v1路由模块
"""

from fastapi import APIRouter
from ...core.versioning import versioned_api, get_version_info

# 创建各个子模块的路由
from .tts import router as tts_router
from .audiobook import router as audiobook_router
from .streaming import router as streaming_router
from .video import router as video_router
from .auth import router as auth_router

# 创建主路由
def create_api_router() -> APIRouter:
    """创建API v1路由"""
    router = APIRouter()
    
    # 包含各个子模块路由
    router.include_router(auth_router, prefix="/auth", tags=["认证"])
    router.include_router(tts_router, prefix="/tts", tags=["语音合成"])
    router.include_router(audiobook_router, prefix="/audiobooks", tags=["有声读物"])
    router.include_router(streaming_router, prefix="/streaming", tags=["音频流"])
    router.include_router(video_router, prefix="/video", tags=["视频配音"])
    
    # 版本信息端点
    @router.get("/info")
    async def get_api_info():
        """获取API信息"""
        return {
            "version": "1",
            "title": "Offline Language Player API v1",
            "description": "离线语言播放系统第一版API",
            "is_stable": True,
            "endpoints": {
                "tts": "/tts",
                "audiobooks": "/audiobooks", 
                "streaming": "/streaming",
                "video": "/video"
            }
        }
        
    # 添加健康检查端点在API v1路由中
    @router.get("/health")
    async def api_health_check():
        """API健康检查"""
        from ...core.database import check_database_health
        
        # 检查数据库健康状态
        db_health = await check_database_health()
        
        # 返回健康状态
        return {
            "status": "healthy",
            "version": "1.0.0",
            "database": db_health,
            "components": {
                "api": "online",
                "database": "online" if db_health["status"] == "healthy" else "issues"
            }
        }
    
    return router

# 创建并导出主路由
api_router = create_api_router()

# 应用版本化装饰器
api_router = versioned_api(
    version="1",
    title="Offline Language Player API v1",
    description="离线语言播放系统第一版API，提供语音合成、有声读物、音频流和视频配音功能",
    is_stable=True
)(api_router)

# 导出版本信息
__version__ = "1.0.0"
